<%--
  Created by IntelliJ IDEA.
  User: Tec
  Date: 2023/11/16
  Time: 17:00
  To change this template use File | Settings | |Editor | File and Code Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.util.*, cn.estore.entity.CustomerEntity, cn.estore.dao.CustomerDao,cn.estore.util.Encrypt" %>

<html>
<head>
    <title>Title</title>
</head>
<body>
<div align="center">
    <%
        CustomerDao dao = new CustomerDao();
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        String password = Encrypt.hashPassword(request.getParameter("password").trim());
        CustomerEntity customer = dao.selectCustomerByName(name);
        if (customer == null || customer.equals("")) {
    %>
    <script>
        alert("用户不存在，请重新登录！");
        window.history.go(-1);
    </script>
    <%
    } else {
        if (customer.getPassword().equals(password)) {
            session.setAttribute("user", customer);
            session.setAttribute("name", name);
            response.sendRedirect("/estore_temp/pages/product/main.jsp");
        } else {
            System.out.println(password);
            System.out.println(name);
            System.out.println(customer.getPassword());
    %>
    <script>
        alert("密码错误，请重新登录！");
        window.history.go(-1);
    </script>
    <%
            }
        }
    %>
</div>
</body>
</html>
